package it.ap.sa.core.confservice.event;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import it.ap.sa.core.configuration.policy.IPolicyLoader;
import it.ap.sa.core.utils.CoreProperties;
import it.ap.sa.core.utils.SpringContextProvider;

/**
 * @author Alessandro Paolillo
 */
@Component
public class ApplicationEnvironmentSetup implements ApplicationListener<ContextRefreshedEvent> {

	private static final Logger logger = LoggerFactory.getLogger(ApplicationEnvironmentSetup.class.getName());

	@Autowired
	private ApplicationEventPublisher publisher;
	
	@Autowired
	private CoreProperties property;
	
	/** necessario per evitare di reinizializzare il tutto **/
	public static Boolean initilized = false;
	
	/**
	 * This method is called during Spring's startup.
	 * 
	 * @param event
	 *            Event raised when an ApplicationContext gets initialized or
	 *            refreshed.
	 */
	@Override
	public void onApplicationEvent(final ContextRefreshedEvent event) {
		if(!initilized){
			logger.info(">>>>>>>>>>>>>>>>>>>>>>> Setup dell'ambiente ... IN CORSO <<<<<<<<<<<<<<<<< ");
			
			/** ricorda inizializzazione **/
			initilized = true;
			
			logger.info(">>>>>>>>>>>>>>>>>>>>>>> Setup dell'ambiente ... TERMINATO <<<<<<<<<<<<<<<<< ");
		}
	}
}
